﻿using FlowCanvas;
using FlowCanvas.Nodes;
using Yoozoo.Core.Timeline;

namespace Yoozoo.Gameplay.Liberty.Nodes
{
    public class DestroyTimelineConstructor : CallableActionNodeBase
    {
        protected override void OnRegisterPorts(FlowNode node)
        {
            var o = node.AddFlowOutput("Out");
            var p1 = node.AddValueInput<TimelineConstructor>("TimelineConstructor");
            
            node.AddFlowInput("In", (Flow f) => { Invoke(p1.value); o.Call(f); });
        }

        private void Invoke(TimelineConstructor constructor)
        {
            if (constructor)
            {
                TimelineConstructorMgr.GetInstance("TimelineConstructorMgr")?.RemoveConstructor(constructor);
                TimelineConstructorMgr.GetInstance("TimelineConstructorMgr")?.DestroyConstructor(constructor);
            }
        }
    }
}